package com.dc.dao;

import com.dc.dao.vo.WorkflowChartVO;
import com.dc.entity.ShipRepairEntity;
import com.dc.entity.WorkflowTopFirstEntity;
import com.dc.entity.WorkflowTopSecondEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface WorkflowTopFirstDao extends JpaRepository<WorkflowTopFirstEntity, Long>, JpaSpecificationExecutor<WorkflowTopFirstEntity> {

    List<WorkflowTopFirstEntity> findByShipRepairEntity(ShipRepairEntity shipRepair);

    @Query(nativeQuery = true, value = "SELECT ship_repair_id as shipRepairId, sum(c_shen) as value FROM t_workflow_stat_first where ship_repair_id in (:sids) GROUP BY ship_repair_id ORDER BY value limit 10")
    List<WorkflowChartVO> findShipShenChart(@Param("sids")  List<Long> sids);  // repairId list

    @Query(nativeQuery = true, value = "SELECT ship_repair_id as shipRepairId, sum(c_ocean) as value FROM t_workflow_stat_first where ship_repair_id in (:sids) GROUP BY ship_repair_id ORDER BY value limit 10")
    List<WorkflowChartVO> findShipOceanChart(@Param("sids") List<Long> sids);

    @Query(nativeQuery = true, value = "SELECT ship_repair_id as shipRepairId, c_shen as value FROM t_workflow_stat_first WHERE energy_category = :energyCategory and ship_repair_id in (:sids)  ORDER BY value limit 10")
    List<WorkflowChartVO> findEnergyShenChart(@Param("sids") List<Long> sids, @Param("energyCategory") String energyCategory);

    @Query(nativeQuery = true, value = "SELECT ship_repair_id as shipRepairId, c_ocean as value FROM t_workflow_stat_first WHERE energy_category = :energyCategory and ship_repair_id in (:sids) ORDER BY value limit 10")
    List<WorkflowChartVO> findEnergyOceanChart(@Param("sids") List<Long> sids, @Param("energyCategory") String energyCategory);

}
